package com.artPreter.service.impl;


import com.artPreter.mapper.EventExhibitionContentSectionMapper;
import com.artPreter.pojo.EventExhibitionContentSection;
import com.artPreter.pojo.EventExhibitionContentSection;
import com.artPreter.pojo.EventExhibitionSectionTemp;
import com.artPreter.service.IEventExhibitionContentSectionService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * <p>
 * 活动展览栏目内容表 服务实现类
 * </p>
 *
 * @author jarvis
 * @since 2025-01-07
 */
@Service
public class EventExhibitionContentSectionServiceImpl extends ServiceImpl<EventExhibitionContentSectionMapper, EventExhibitionContentSection> implements IEventExhibitionContentSectionService {

    @Override
    public List<EventExhibitionContentSection> getList(EventExhibitionContentSection eventExhibitionContentSection) {
        if(eventExhibitionContentSection.getEventId()!=null&&eventExhibitionContentSection.getSectionId()!=null){
            LambdaQueryWrapper<EventExhibitionContentSection> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(EventExhibitionContentSection::getEventId,eventExhibitionContentSection.getEventId());
            queryWrapper.eq(EventExhibitionContentSection::getSectionId,eventExhibitionContentSection.getSectionId());
            return this.baseMapper.selectList(queryWrapper);
        }
        return null;
    }

    @Override
    public void edit(EventExhibitionContentSection eventExhibitionContentSection) {
        if(eventExhibitionContentSection.getId()==null){
            return;
        }
        EventExhibitionContentSection item = new EventExhibitionContentSection();
        item.setContent(eventExhibitionContentSection.getContent());
        item.setId(eventExhibitionContentSection.getId());
        this.baseMapper.updateById(item);
    }

    @Override
    public void addContent(EventExhibitionSectionTemp eventExhibitionSectionTemp) {
        if(eventExhibitionSectionTemp.getContentType()!=null){
            String str = eventExhibitionSectionTemp.getContentType().toString();
            for (int i = 0; i < str.length(); i++) {
                String c = String.valueOf(str.charAt(i));
                EventExhibitionContentSection eventExhibitionContentSection = new EventExhibitionContentSection();
                String uuid = UUID.randomUUID().toString();
                // 内容uuid
                eventExhibitionContentSection.setContentId(uuid);
                // content_type 内容类型 1:简介类型 2:艺术家列表 3:艺术品列表 4:图片类型 5:资讯类型 6:超链接
                eventExhibitionContentSection.setContentType(Integer.parseInt(c));
                // index_num  板块顺序
                eventExhibitionContentSection.setIndexNum(i);
                // section_id  板块uuid
                eventExhibitionContentSection.setSectionId(eventExhibitionSectionTemp.getSectionId());
                // name  内容名称
                String name = "";
                switch (c){
                    case "1":
                        name= "单页";
                        break;
                    case "2":
                        name= "艺术家列表";
                        break;
                    case "3":
                        name= "艺术品列表";
                        break;
                    case "4":
                        name= "图片列表";
                        break;
                    case "5":
                        name= "资讯列表";
                        break;
                    case "6":
                        name= "超链接列表";
                        break;
                }
                eventExhibitionContentSection.setName(eventExhibitionSectionTemp.getName()+name);
                eventExhibitionContentSection.setEventId(eventExhibitionSectionTemp.getEventId());
                this.baseMapper.insert(eventExhibitionContentSection);

            }
        }
    }
}
